package com.lgx.common.dao.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import com.lgx.common.basic.dao.GeneralDao;
import com.lgx.common.dao.ICityDictonaryDao;
import com.lgx.common.entity.CityDictonary;

@Component
public class CityDictonaryDao extends GeneralDao implements ICityDictonaryDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<CityDictonary> findCityDictonaryList(String type,
			String parentId) {
		String hql = "from CityDictonary d where d.isDelete = '0'";
		if(!StringUtils.isEmpty(type)){
			hql += " and d.type = '"+type+"'";
		}
		if(!StringUtils.isEmpty(parentId)){
			hql += " and d.parent.id = '"+parentId+"'";
		}
		
		hql += " order by d.code asc";
		return this.getHibernateTemplate().find(hql);
	}
	
	@Override
	public List<?> findCityDictonaryList(String id) {
		String sql = "select d.name from CityDictonary d where d.isDelete = '0'";
		if(!StringUtils.isEmpty(id)){
			sql += " and d.id = "+id;
		}
		sql += "  order by d.code asc";
		return this.getHibernateTemplate().find(sql);
	}

}
